package com.yl.zqy.controller.login;

import cn.dev33.satoken.stp.StpUtil;
import com.yl.zqy.common.Result;
import com.yl.zqy.dto.SysMenuDTO;
import com.yl.zqy.entity.sys.SysUser;
import com.yl.zqy.service.login.LoginService;
import com.yl.zqy.service.sys.SysMenuService;
import com.yl.zqy.vo.login.LoginVo;
import com.yl.zqy.vo.login.UserPwdVo;
import com.yl.zqy.vo.user.UserInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 登录控制器
 *
 * @author liang.yu
 * @since 2024-03-24
 */
@RestController
@RequestMapping("/acc/")
@RequiredArgsConstructor
@Tag(name = "登录管理", description = "LoginController")
public class LoginController {
    private final LoginService loginService;
    private final SysMenuService menuService;

    @PostMapping("/doLogin")
    @Operation(summary = "登录", tags = "登录管理")
    public Result<UserInfoVo> doLogin(@RequestBody LoginVo vo) {
        return loginService.login(vo);
    }

    @GetMapping("/logout")
    @Operation(summary = "退出", tags = "登录管理")
    public void logout() {
        loginService.logout();
    }

    @GetMapping("/getSubject")
    @Operation(summary = "获取当前用户信息", tags = "登录管理")
    public Result<UserInfoVo> getSubject() {
        return loginService.getSubject();
    }

    @PostMapping("/updatePwd")
    @Operation(summary = "修改密码", tags = "登录管理")
    public Result<Boolean> updatePwd(@RequestBody UserPwdVo vo) {
        return loginService.updatePwd(vo);
    }

    @GetMapping("/menus")
    @Operation(summary = "获取菜单", tags = "登录管理")
    public Result<List<SysMenuDTO>> menus() {
        return loginService.getMenus();
    }

    @GetMapping("/permissions")
    @Operation(summary = "获取权限编码", tags = "登录管理")
    public Result<List<String>> getPermission(){
        return loginService.getPermission();
    }

}
